package com.huanwei.login_regist;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.github.czy1121.view.RoundButton;
import com.huanwei.mini.R;
import com.huanwei.mini.http.API;
import com.huanwei.mini.http.GeRen;
import com.huanwei.mini.http.Zhuce;
import com.huanwei.mini.utils.JSONUtils;
import com.huanwei.mini.utils.Okhttp;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class XiuGaiActivity extends AppCompatActivity {


    @BindView(R.id.textView11)
    TextView textView11;
    @BindView(R.id.tv_value_name)
    EditText tvValueName;
    @BindView(R.id.layout_help)
    RelativeLayout layoutHelp;
    @BindView(R.id.tv_xingbie)
    TextView tvXingbie;
    @BindView(R.id.tv_value_xingbie)
    EditText tvValueXingbie;
    @BindView(R.id.textView12)
    TextView textView12;
    @BindView(R.id.tv_value_zhuzhi)
    EditText tvValueZhuzhi;
    @BindView(R.id.layout_about)
    RelativeLayout layoutAbout;
    @BindView(R.id.tv_dianhua)
    TextView tvDianhua;
    @BindView(R.id.tv_value_dianhua)
    EditText tvValueDianhua;
    @BindView(R.id.tv_shenfenzheng)
    TextView tvShenfenzheng;
    @BindView(R.id.tv_value_shenfenzheng)
    EditText tvValueShenfenzheng;
    @BindView(R.id.tv_bumen)
    TextView tvBumen;
    @BindView(R.id.tv_value_bumen)
    EditText tvValueBumen;
    @BindView(R.id.tv_gangwei)
    TextView tvGangwei;
    @BindView(R.id.tv_value_gangwei)
    TextView tvValueGangwei;
    @BindView(R.id.change)
    RoundButton change;

    @BindView(R.id.activity_seetting)
    LinearLayout activitySeetting;
    @BindView(R.id.img_back)
    RelativeLayout imgBack;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_xiugai);
        ButterKnife.bind(this);
        geren();
    }

    public void geren() {
        API.GR(XiuGaiActivity.this, new Okhttp.Objectcallback() {
            @Override
            public void onsuccess(String st) {
                Log.e("xxx", "xx" + st);
                GeRen geRen = JSONUtils.parseJSON(st, GeRen.class);
                setGeRen(geRen);

            }

            @Override
            public void onFalia(int code, String errst) {
                Log.e("xxx", "xx" + errst);
            }
        });
    }

    public void setGeRen(GeRen geRen) {
        GeRen.DataBean data = geRen.getData();
        tvValueName.setText(data.getNames());
        tvValueDianhua.setText(data.getIphone());
        tvValueBumen.setText(data.getXm());
        tvValueGangwei.setText(data.getDs());
        tvValueShenfenzheng.setText(data.getMbnumber());
        tvValueZhuzhi.setText(data.getFaddress());
        tvValueXingbie.setText("" + data.getMbsex());
    }


    @OnClick({R.id.img_back, R.id.change})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.change:
                String names = tvValueName.getText().toString();
                String hometel = tvValueName.getText().toString();
                String mbnumber = tvValueShenfenzheng.getText().toString();
                String tel = tvValueDianhua.getText().toString();
                String faddress = tvValueZhuzhi.getText().toString();
                API.Saveuserinfo(XiuGaiActivity.this,
                        names,
                        hometel,
                        mbnumber,
                        tel,
                        faddress, new Okhttp.Objectcallback() {
                            @Override
                            public void onsuccess(String st) {
                                Log.e("xxx", "xx"+st);
                                Zhuce zhuce = JSONUtils.parseJSON(st, Zhuce.class);
                                if (zhuce.getError()==0) {
                                    Toast.makeText(XiuGaiActivity.this, ""+zhuce.getMsg(), Toast.LENGTH_SHORT).show();
                                    finish();
                                } else {
                                    Toast.makeText(XiuGaiActivity.this, ""+zhuce.getMsg(), Toast.LENGTH_SHORT).show();
                                }


                            }

                            @Override
                            public void onFalia(int code, String errst) {
                                Log.e("xxx", "xx"+errst);
                            }
                        });
                break;
        }
    }

    //切换岗位
}
